package com.example.demo1.test;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.UUID;

/**
 * @author sunjk
 * @since 2020/9/3
 */
@Component
public class Sender {

    @Autowired
    private AmqpTemplate amqpTemplate;

    @Autowired
    private RabbitTemplate rabbitTemplate;
    /*public void send () {
        System.out.println("生产者开始生产消息");
        amqpTemplate.convertAndSend("hello", "我生产的消息！");
    }*/

    public void send2(){
        String id = UUID.randomUUID().toString();
        CorrelationData correlationData = new CorrelationData(id);
        rabbitTemplate.convertAndSend("exchange", "topic.message", "topic.message消息", correlationData);
    }

    // rotkey * 一个单词 # 零个或多个
    public void send3() {
        String id = UUID.randomUUID().toString();
        CorrelationData correlationData = new CorrelationData(id);
        rabbitTemplate.convertAndSend("exchange", "topic.hello", "topi.*消息", correlationData);
    }

}
